<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * Employees model
 *
 * @author chientran@vietnambiz.com
 */
class Home_model extends MY_Model{
	
        
	function  __construct(){
		parent::__construct();
	}

    
	function get_array($id = NULL, $offset = 0, $limit = 0) {
		$this->db->select('*')->from(TBL_USER);
                $this->db->order_by('typeid','desc');
		if (is_null($id)) {		
			if ($limit > 0) {
				$this->db->limit($limit, $offset);
			}
			return $this->db->get()->result_array();
		} else {
			return $this->db->where('id', intval($id))->get()->row_array();
		}
	}
        
        function get_array_by_condition($array = NULL, $offset = 0, $limit = 0) {
		$this->db->select('*')->from(TBL_USER);
                 $this->db->order_by('typeid','desc');
		if (is_null($array)) {		
			if ($limit > 0) {
				$this->db->limit($limit, $offset);
			}
			return $this->db->get()->result_array();
		} else {                       
			$this->db->where($array, $limit, $offset);
                        return $this->db->get()->result_array();
		}
	}
	
	function get_count_all() {
		return $this->db->from(TBL_USER)->count_all_results();
	}

	/**
	 * Add / Update employees
	 * @param array $employee
	 * @return int|boolean
	 */
	function update($array){
		if (is_array($array)) {
			if (!is_null($array['id'])) {
				$this->db->where('id', $array['id'])->update(TBL_USER, $array);
				return $array['id'];
			} else {
				$this->db->insert(TBL_USER, $array);
				return $this->db->insert_id();
			}
		}
		return false;
	}
	
	/**
	 * Delete employee
	 * @param int $employeeNumber
	 * @return boolean
	 */
	function delete($id = NULL) {
		if (!is_null($id)) {
			$this->db->where('id', $id)->delete(TBL_USER);
			return true;
		}
		return false;
	}
}